import Adafruit_DHT
import time

DHT11_SENSOR = Adafruit_DHT.DHT11
DHT11_PIN = 17

humidity, temperature = Adafruit_DHT.read(DHT11_SENSOR, DHT11_PIN)

def temp(temperature):
    tmp_data = open("/home/pi/Desktop/onenet/tmp_data.txt","w")
    if temperature is not None:
        temperature = str(temperature)
        print("temp = " + temperature)
        tmp_data.write(temperature)
        tmp_data.close()
    return temperature

def humi(humidity):
    hum_data = open("/home/pi/Desktop/onenet/hum_data.txt","w")
    if humidity is not None:
        #print("温度={0:0.1f}℃ 湿度={1:0.1f}%".format(temperature,humidity))
        humidity = str(humidity)
        print("humi = " + humidity)
        hum_data.write(humidity)
        hum_data.close()
    return humidity


if __name__ == '__main__':
    tempe = temp(temperature)
    hum = humi(humidity)
    print(tempe)
    print (hum)

